/**
 * 玩家页面JS脚本
 */

$(function () {
	//验证密码输入是否一直    
	$.extend($.fn.validatebox.defaults.rules, {    
	    equals: {    
	        validator: function(value,param){
	            return value == $(param[0]).val();    
	        },    
	        message: '密码输入前后不一致!'  
	    }    
	});
	
	$('#user_dg').datagrid({
		url: basePath+"user/queryUserPage.do",
		pagination:true,
		rownumbers:true,
		fit:true,
		//singleSelect:true,
		columns:[[    
    	        {field:'yid',title:'操作',checkbox:true},    
    	        {field:'yaccountid',title:'账户ID',width:80,align:'center'},    
    	        {field:'yrealname',title:'姓名',width:80,align:'center'},    
    	        {field:'ynikename',title:'昵称',width:80,align:'center'},   
    	        {field:'yphonenumber',title:'电话',width:80,align:'center'},   
    	        {field:'ycratedatetime',title:'注册时间',width:80,align:'center'}   
    	    ]],
		striped:true,
		align:'right',
        toolbar:[{//正上方工具栏  
            text:'添加',  
            iconCls:'icon-add',  
            handler:function(){  
            	$('#playerAddDialog').window('open');
           	}  
        },'-',{
            text:'修改',  
            iconCls:'icon-edit',  
            handler:function(){  
            	var rows = $('#user_dg').datagrid('getSelections');
            	if(rows.length == 0){
            		$.messager.alert('提示','请选择要修改的数据','info');
            	}else{
            		$('#playerAddDialog').window('open');
            		$("#yid").val(rows[0].yid);
            		$("#playerName").val(rows[0].yrealname);
            		$("#playerNikename").val(rows[0].ynikename);
            		$("#playerPhone").val(rows[0].yphonenumber);
            	}
            }
		},'-',{  
			text:'删除',  
			iconCls:'icon-cancel',  
			handler:function(){  
				//batch('delete'); 
				$.messager.alert('提示','一般不考虑物理删除所以。。。！','info');
			}
		}]
	});
});

//提交表单
function sub(){
	var isValid = $("#playerForm").form('validate');
	//验证表单是否符合要求
	if(!isValid){
		$.messager.alert('提示','请正确填写相关信息！','info');
		return false;
	}    		
	
	//提交表单
	$.ajax({
		   type: 'POST',
		   url: path +'/user/addUser.do',
		   data: $("#playerForm").serialize(),
           async: false,
           error: function(request) {
        	   $.messager.alert('提示','保存失败！');
           },
		   success: function(msg){
			   $("#user_dg").datagrid("reload");
			   $('#playerAddDialog').window('close');
			   $.messager.alert('提示','保存成功！');
			   $("#playerForm").form('reset');
		   }
	});
}

//关闭弹出窗口
function cancel(winID){
	$('#'+winID).window('close');
}